<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <ul class="topnav">
        <li>Item1</li>
        <li>
            <ul>
                <li>chiled Item1 </li>
                <li>chiled Item2</li>
                <li>chiled Item3 </li>
            </ul>
        </li>

        <li>Item3</li>
    </ul>

    <script>
        /*    //js写法
        //1.给所有ul标签下的li标签添加一个边框(直接子元素)
        var topnav = document.getElementsByClassName("topnav")[0];
        //2.读取到topnav下面的子元素 
        var children = topnav.childNodes;
        console.log(children);
        for (var i = 0; i < children.length; i++) {
            if (children[i].nodeName !=="#text") {
                children[i].style.border = "3px soild red"
            }
        }   */




        //2.给所有ul标签下的li标签添加一个边框(后代元素)
        var topnav=document.getElementsByClassName("topnav")[0];
        var children=topnav.getElementsByTagName("li");
            for(var i=0;i<children.length;i++){
                children[i].style.border="3px soild green"
            }
    </script>
</body>

</html>